﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Pg.BioMedics.SDR.Entities;
using Pg.BioMedics.SDR.Services;
using Pg.BioMedics.SDR.Web.Controls;
using Pg.BioMedics.SDR.Web.Constants;

public partial class Administration_Views_SetPasswordView : BaseHostedView
{
    #region Fields

    private IManagementService managementService;

    private Person person;

    #endregion

    #region Properties

    /// <summary>
    /// Sets managment service instance. Utilized by IoC context for 
    /// managment service delivery to this view
    /// </summary>
    public IManagementService ManagmentService
    {
        set
        {
            this.managementService = value;
        }
    }

    #endregion

    #region Event handlers

    protected override void LoadParameters(object[] parameters)
    {
        this.person = parameters.FirstOrDefault() as Person;
    }

    protected void saveLinkButton_Click(object sender, EventArgs e)
    {
        try
        {
            this.managementService.Activate(this.person, passwordTextBox.Text);
            base.Return(this.person);
        }
        catch (Exception ex)
        {
            base.Navigate(UsersManagementViews.ErrorView, ex);
        }
    }

    protected void returnLinkButton_Click(object sender, EventArgs e)
    {
        base.Return(this.person);
    }

    #endregion

    #region Overriden methods

    protected override object SaveViewModel()
    {
        return this.person;
    }

    protected override void LoadViewModel(object savedModel)
    {
        if (savedModel != null)
            this.person = savedModel as Person;
    }

    #endregion    
}
